;(function() {
	Nokia.WikipediaItemView = Nokia.View.extend({
		
		/*
		 * Initializes the Guarana components
		 */
		init: function()
		{
			var instance = this;
			
			this.contentElement = this.getContainer().find('#wikipedia-item-content');
			
			this.itemOpenButton = new Nokia.Button({
				element: '#wikipedia-item-open-button',
				label: 'Full Article',
				width: '50%',
				click: function() {
					instance.openInWebBrowser();
				}
			});
		},
		
		/*
		 * Opens the original Wikipedia article Web page
		 */
		openInWebBrowser: function()
		{
			widget.openURL('http://' + this.item.wikipediaUrl);
		},
		
		/*
		 * Shows a Wikipedia result item
		 */
		showItem: function(item)
		{
			this.item = item;

			var itemHTML = Nokia.GBCServices.getServiceItemSnippet(item);
			
			itemHTML += '<div class="clearer item-detail-text" id="wikipedia-item-text"></div>' + 
				'<p id="wikipedia-item-text-content">' + item.summary + '</p>';

			this.contentElement.html(itemHTML);
			
			new Nokia.TextLabel({
				element: '#wikipedia-item-text',
				content: '#wikipedia-item-text-content'
			});
		},
		
		/*
		 * Shows the view, populating it with the given Wikipedia result item
		 */
		show: function(item)
		{
			// Replace the Exit button with a Back button
			
			var template = this.getTemplate();
			var topBar = template.getHeaderTopBar();
			var viewManager = template.getViewManager();
			
			var defaultTopItems = GBC.getDefaultTopItems();
			
			defaultTopItems[0] = {classname: 'nokia-template-header-icon-back', callback: function() { viewManager.back() }};
			
			topBar.setItems(defaultTopItems);
			
			this.showItem(item);
			
			this.getContainer().show();
		}
	});
})();